from sqlalchemy import event

from .ctfModel import CtfRedBlueScore


@event.listens_for(CtfRedBlueScore, "before_insert")
def before_insert_trigger(mapper, connection, target):
    """角色插入时对角色ID进行检查"""
    pass
    # print(target.__dict__)
    # current_app.logger.warning(f"before_insert: {target.score}")
    # current_app.logger.warning(f"before_insert: {target.link_score_info}")
    # raise ValueError("数据错误")
    # pass


# @event.listens_for(CtfRedBlueScore, 'before_update')
# def before_update_trigger(mapper, connection, target):
#     """角色更新时对角色ID进行检查"""
#     current_app.logger.warning(f"before_update: {target.score}")
#     current_app.logger.warning(f"before_update: {target.link_score_info}")
#     pass


# from sqlalchemy.schema import ColumnCollectionConstraint
# from sqlalchemy.engine import Engine
# from sqlalchemy import event
#
# @event.listens_for(Engine, "before_cursor_execute", retval=True)
# def comment_sql_calls(conn, cursor, statement, parameters,
#                                     context, executemany):
#     a = 1
#     pass
